package k2_oop.p9_collection.demo01;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class UseHashMap {
    public static void main(String[] args) {

        HashMap<String,Object> map = new HashMap<>();

        map.put("name","tom");
        map.put("age",20);
        map.put("gender","男");

        map.putIfAbsent("age",30);

        System.out.println(map.get("name"));
        System.out.println(map);

        System.out.println(map.containsKey("name"));
//        if(map.containsKey("name")){
//            System.out.println(map.get("name"));
//        }

        map.replace("name","aaa","jerry");
        System.out.println(map.get("name"));

        Set<String> keySet = map.keySet();
        System.out.println(keySet);

        Collection<Object> valueCollection = map.values();
        System.out.println(valueCollection);

        Set<Map.Entry<String, Object>> entries = map.entrySet();
        for (Map.Entry<String, Object> entry : entries) {
            System.out.println(entry.getKey() + "====" + entry.getValue());
        }
    }
}
